import java.util.List;
import java.util.Scanner;

/**
 * @author yexy
 * @date 2020/6/15 12:14 下午
 * @description
 */
public class StudentSystem {

    //系统运行
    public static void run(){
        StudentManage studentManage = new StudentManage();
        Scanner scanner = new Scanner(System.in);
        boolean flag = true;

        do {
            login(studentManage);
            int operation = scanner.nextInt();

            switch (operation){
                case 1:
                    add(scanner,studentManage);
                    break;
                case 2:
                    query(scanner,studentManage);
                    break;
                case 3:
                    modify(scanner,studentManage);
                    break;
                case 4:
                    delete(scanner,studentManage);
                    break;
                case 5:
                    flag = false;
                    break;

            }

        }while (flag);

    }

    //系统初始界面
    static void login(StudentManage studentManage){
        System.out.println("------------------------------------------");
        System.out.println("--------------学生信息管理系统--------------");
        System.out.println("------------------------------------------");
        System.out.println("-----------------学生列表-------------------");
        System.out.println(studentManage.show());
        System.out.println("------------------------------------------");
        System.out.println("请选择要进行的操作：");
        System.out.println("1.添加");
        System.out.println("2.查询");
        System.out.println("3.修改");
        System.out.println("4.删除");
        System.out.println("5.退出");
    }

    //添加
    static void add(Scanner scanner,StudentManage studentManage) {
        Student s = new Student();
        System.out.println("------------------------------------------");
        System.out.println("------------------------------------------");
        System.out.println("请输入学号：");
        s.setNo(scanner.next());
        System.out.println("请输入姓名：");
        s.setName(scanner.next());
        System.out.println("请输入年龄：");
        s.setAge(scanner.nextInt());
        studentManage.add(s);
    }

    //查询
    static void query(Scanner scanner,StudentManage studentManage){
        System.out.println("------------------------------------------");
        System.out.println("------------------------------------------");
        System.out.println("----------------请选择操作------------------");
        System.out.println("1.学号查找");
        System.out.println("2.姓名查找");
        System.out.println("3.年龄查找");

        int operation = scanner.nextInt();
        switch (operation){
            case 1:
                System.out.println("----------------请输入学号------------------");
                Student student = studentManage.getByNo(scanner.next());
                System.out.println("----------------查询结果是------------------");
                System.out.println(student);
                break;
            case 2:
                System.out.println("----------------请输入姓名------------------");
                List studentName = studentManage.queryByName(scanner.next());
                System.out.println("----------------查询结果是------------------");
                System.out.println(studentManage.show(studentName));
                break;
            case 3:
                System.out.println("----------------请输入年龄------------------");
                List studentsAge = studentManage.queryByAge(scanner.nextInt());
                System.out.println("----------------查询结果是------------------");
                System.out.println(studentManage.show(studentsAge));
                break;
        }

    }

    //修改
    static void modify(Scanner scanner,StudentManage studentManage){
        System.out.println("------------------------------------------");
        System.out.println("------------------------------------------");
        System.out.println("-----------------学生列表-------------------");
        System.out.println(studentManage.show());
        System.out.println("-----------请输入要修改学生的学号-------------");
        Student qryS = studentManage.getByNo(scanner.next());
        System.out.println(qryS);
        System.out.println("-----------请输入该学生修改后的姓名------------");
        qryS.setName(scanner.next());
        System.out.println("-----------请输入该学生修改后的年龄------------");
        qryS.setAge(scanner.nextInt());

    }

    //删除
    static void delete(Scanner scanner,StudentManage studentManage){
        System.out.println("------------------------------------------");
        System.out.println("------------------------------------------");
        System.out.println(studentManage.show());
        System.out.println("-----------请输入要删除学生的学号-------------");
        studentManage.deleteByNo(scanner.next());
    }
}
